package com.my.dao;

import com.my.UserInfo;
import com.my.util.DBCon;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserInfoModel {
    private DBCon dbCon;
    public UserInfoModel(){dbCon=new DBCon();}
    public boolean insert(UserInfo userInfo) {
        boolean result = false;
        Connection con = dbCon.getConnection();
        String sql = "insert into tb_userInfo(userName,password,address)values(?,?,?)";
        try {
            PreparedStatement pstmt = con.prepareStatement(sql);
            pstmt.setString(1, userInfo.getUserName());
            pstmt.setString(2, userInfo.getPassword());
            pstmt.setString(3, userInfo.getAddress());
            int i = pstmt.executeUpdate();
            if (i > 0) {
                result = true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }
}

